import request from '@/utils/request';
import type { AddressForm, AddressVO } from '@/api/user/address/types';
import type { AxiosPromise } from 'axios';

/**
 * 收货地址列表
 * @param id
 * @param query
 */

const baseUrl = '/api/user/address';
export const getAddressListApi = (query?: any): AxiosPromise<AddressVO[]> => {
  return request({
    url: baseUrl + `/list`,
    method: 'get',
    params: query
  });
};
/**
 * 收货地址列表
 * @param id
 * @param query
 */
export const getAddressApi = (id: string | number): AxiosPromise<AddressVO[]> => {
  return request({
    url: baseUrl + `/${id}`,
    method: 'get'
  });
};
/**
 * 新增收货地址
 * @param data
 */
export const addAddressApi = (data: AddressForm) => {
  return request({
    url: baseUrl,
    method: 'post',
    data: data
  });
};

/**
 * 修改收货地址
 * @param data
 */
export const updateAddressApi = (data: AddressForm) => {
  return request({
    url: baseUrl,
    method: 'put',
    data: data
  });
};
/**
 * 设置默认收货地址
 * @param id
 */
export const updateDefaultApi = (id: string | number) => {
  return request({
    url: baseUrl + `/updateStatus/${id}`,
    method: 'put'
  });
};
